﻿using Hallenberg.Core.Globalization;
using Hallenberg.SmartClient.Services;
using NUnit.Framework;

namespace Hallenberg.SmartClient.Test.Services
{
    [TestFixture]
    public class ResourceCacheTest
    {
        [Test]
        public void CanCreateResourceCache()
        {
            var cache = new ResourceCache();
        }

        [Test]
        public void ShouldReturnAString()
        {
            var cache = new ResourceCache();
            string resourceValue = cache.GetString("TestMenuTitle", typeof(Properties.Resources));

            Assert.That(resourceValue, Is.Not.Empty);
        }

        [Test]
        public void ShouldReturnEnglishString()
        {
            ChangeLanguageAndAssertMenuTitle("en-US", "The Menu Title");
        }

        [Test]
        public void ShouldReturnDanishString()
        {
            ChangeLanguageAndAssertMenuTitle("da-DK", "Danish Menu Title");
        }

        private void ChangeLanguageAndAssertMenuTitle(string languageName, string menuTitle)
        {
            using (ChangeThreadCulture threadCulture = new ChangeThreadCulture(languageName))
            {
                var cache = new ResourceCache();
                string resourceValue = cache.GetString("TestMenuTitle", typeof(Properties.Resources));

                Assert.That(resourceValue, Is.Not.Empty);
                Assert.That(resourceValue, Is.EqualTo(menuTitle));
            }
        }
    }
}
